package com.app.view;


import android.content.Context;
import android.support.v4.widget.NestedScrollView;
import android.util.AttributeSet;

public class ObserveNestedScrollView  extends NestedScrollView{
	 private OnScrollChangedCallback mOnScrollChangedCallback;
	    public ObserveNestedScrollView(final Context context) {
	        super(context);
	    }
	 
	    public ObserveNestedScrollView(final Context context, final AttributeSet attrs) {
	        super(context, attrs);
	    }
	 
	    public ObserveNestedScrollView(final Context context, final AttributeSet attrs,
	                             final int defStyle) {
	        super(context, attrs, defStyle);
	    }
	 
	    @Override
	    protected void onScrollChanged(final int l, final int t, final int oldl,
	                                   final int oldt) {
	        super.onScrollChanged(l, t, oldl, oldt);
	 
	        if (mOnScrollChangedCallback != null) {
	            mOnScrollChangedCallback.onScroll(l - oldl, t - oldt);
	        }
	    }
	 
	    public OnScrollChangedCallback getOnScrollChangedCallback() {
	        return mOnScrollChangedCallback;
	    }
	 
	    public void setOnScrollChangedCallback(
	            final OnScrollChangedCallback onScrollChangedCallback) {
	        mOnScrollChangedCallback = onScrollChangedCallback;
	    }
	 
	    /**
	     * Impliment in the activity/fragment/view that you want to listen to the webview
	     */
	    public static interface OnScrollChangedCallback {
	        public void onScroll(int dx, int dy);
	    }
}
